package main

import "fmt"

func main() {
	s1 := []int{}
	printSlice(s1)
	s1 = append(s1, 10)
	printSlice(s1)
	s1 = append(s1, 20, 30, 40)
	printSlice(s1)
	for i := 1; i <= 10; i++ {
		s1 = append(s1, i)
		printSlice(s1)
	}
	arr := [10]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
	s2 := arr[:5] //[1,2,3,4,5]
	s3 := arr[2:7] //[3,4,5,6,7]
	fmt.Println(arr)
	printSlice(s2)
	printSlice(s3)
	s2[3]=100
	printSlice(s2)
	printSlice(s3)
	fmt.Println(arr) //上面切片改，数组对应的也改，没得商量，强迫的
	fmt.Printf("%p\n",s2)
	s2=append(s2,1,1,1,1,1,1,1,1,1,1,1)
	printSlice(s2)
	fmt.Printf("%p\n",s2)
	s2[0]=100
	printSlice(s2)
	printSlice(s1)
	printSlice(s3)
	fmt.Println(arr)



	fmt.Println("###############")
	//s4=append(s4,s5)
	//printSlice(s4)
	fmt.Println("-------------")
	s6:=[]int{1,2,3,4,5}
	s7:=[]int{7,8,9}
	printSlice(s6)
	printSlice(s7)
	copy(s7,s6)
	printSlice(s7)

	s4:=[]int{1,2,3,4}
	s5:=make([]int,4,10)
	for i:=0;i<len(s5);i++{
		s5[i]=i*2+1
	}
	fmt.Println(s4)
	fmt.Println(s5)
	s4=append(s4,s5...)
	fmt.Println(s4)

	s4=[]int{1,2,3,4,1,3,5,7}
	index :=3
	s4 =append(s4[:index],s4[index+1:]...) //s4[0:3]123,s4[4:]1357
	fmt.Println(s4)

}
func printSlice(x []int) {
	fmt.Printf("len=%d cap=%d slice=%v type=%T\n", len(x), cap(x), x,x)
}
